package fr.cephb.lexyacc;

/** a Node having at least one child node */
public abstract class YNode extends Node {
	private Node children[];
	/** constructor with the child nodes */
	protected YNode(Node ...nodes)
		{
		this.children=new Node[nodes.length];
		System.arraycopy(this.children, 0, nodes, 0, this.children.length);
		}

	/** return a child by index */
	protected Node at(int i)
		{
		return this.children[i];
		}
	
	/** return the number of children */
	protected int getChildrenCount()
		{
		return this.children.length;
		}
	
	@Override
	public abstract Object eval(Context ctx);

	@Override
	public String toString()
		{
		StringBuilder b= new StringBuilder(getName());
		b.append("(");
		for(int i=0;i< getChildrenCount();++i)
			{
			if(i>0) b.append(",");
			b.append(at(i).toString());
			}
		b.append(")");
		return b.toString();
		}
	
}
